<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>内容审核</el-breadcrumb-item>
        <el-breadcrumb-item> 作品章节审核 </el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <avue-crud
        ref="crud"
        :data="data"
        v-model="form"
        :option="option"
        :page.sync="page"
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-reset="form = {}"
        @search-change="searchChange"
        @selection-change="selectionChange"
      >
        <!-- 自定义 -->
        <template slot-scope="scope" slot="menuLeft">
          <br />
          <!-- <el-tag> 已通过n条 未通过n条 待审核n条</el-tag> -->
        </template>
        <template slot="menuLeft" slot-scope="{ size }">
          <el-button type="success" :size="size" @click="selectSet(1)">通过选中</el-button>
          <el-button type="danger" :size="size" @click="selectSet(0)">拒绝选中</el-button>
        </template>
        <!-- 自定义操作栏 -->
        <template slot-scope="scope" slot="menu">
          <el-button
            icon="el-icon-primary"
            type="text"
            size="small"
            @click.stop="info(scope)"
            >查看</el-button
          >
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { common } from "@/api/cat/httpRequest";
import { catUrl } from "@/config/env";
import { appBookChapterCheck as baseURL, uploadFile } from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      page: {
        total: 0,
        pageSize: 10,
      },
      type: true,
      data: [],
      params: {},
      form: {},
      selectIdList:[],
      default: {
        orderByList: "state&ASC,edit_time&DESC",
        // state : "$in1,2,3"
      },
      option: {
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: false,
        excelBtn: true,
        selection: true,
        border: true,
        border: true,
        column: [
          {
            label: "日期",
            prop: "create_time",
            type: "daterange",
            search: true,
          },
          {
            label: "用户id",
            prop: "user_id",
            type: "input",
          },
          {
            label: "用户昵称",
            prop: "author_name",
            type: "input",
          },
          {
            label: "书籍id",
            prop: "check_book_id",
            type: "input",
          },
          {
            label: "书籍名称",
            prop: "book_title",
            type: "input",
          },
          {
            label: "章节标题",
            prop: "title",
            type: "input",
            search: true,
          },
          {
            label: "审核状态",
            prop: "state",
            type: "select",
            hide: false,
            search: false,
            dicData: [
              {
                label: "<font style='color:red'>待审核</font>",
                value: 1,
              },
              {
                label: "已通过",
                value: 2,
              },
              {
                label: "未通过",
                value: 3,
              },
            ],
          },
          {
            label: "审核状态",
            prop: "states",
            type: "select",
            hide: true,
            search: true,
            dicData: [
              {
                label: "待审核",
                value: 1,
              },
              {
                label: "已通过",
                value: 2,
              },
              {
                label: "未通过",
                value: 3,
              },
            ],
          },
          {
            label: "最后操作信息",
            prop: "edit_time",
            type: "date",
          },
        ],
      },
    };
  },
  methods: {
    async getList() {
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      let response = await common(
        baseURL.pageAndParam,
        { ...this.params, ...this.default },
        this.page,
        "POST"
      );
      this.page = response.page;
      this.data = response.data;
      this.loading = false;
    },
    //查看详情
    info(scope) {
      this.$router.push("/works/worksinfochapter?content_id=" + scope.row.id);
    },
    /**刷新 */
    refreshChange() {
      this.getList();
    },

    /**搜索 */
    searchChange(params, done) {
      params.title = `%${params.title ? params.title : ""}%`;
      params.create_time = `${
        params.create_time ? "!<>!" + params.create_time : ""
      }`;
      params.state = params.states;
      delete params.states;
      this.params = params;
      this.page.currentPage = 1;
      this.getList();
      if (done) done();
    },
    async selectSet(type){
      if(this.selectIdList.length<=0){
          this.$message.error('请先选中')
        return
      }
      this.$confirm('此操作将 '+type==0?'拒绝所有选中':'通过所有选中'+' ,是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          //调用通过或拒绝接口
        let data = await common(`${baseURL.updateSelectBookChapterCheck}`, {state : type==0?3:2 , selectIdList: this.selectIdList}, null, "POST");
        this.getList();
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });          
        });
    },
    selectionChange(list){
        if(list.length<=0){
          this.selectIdList = []
          return
        }
        this.selectIdList = list.map(e=>e.id)
    },
  },
  watch: {
    $route() {
      this.getList();
      // this._initData();//我的初始化方法
    },
  },
  // updated() {
  // 	this.getList();
  // }
};
</script>